﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;


namespace ERP.Classes
{
    public class cs_hmr_loaidonviInfo
    {
        private int _id_loaidonvi;
        private string _tenloai;
        private string _ghichu;
        private int _capthaotac;

        public cs_hmr_loaidonviInfo(int id_loaidonvi, string tenloai, string ghichu, int capthaotac)
        {
            this._id_loaidonvi = id_loaidonvi;
            this._tenloai = tenloai;
            this._ghichu = ghichu;
            this._capthaotac = capthaotac;

        }
        public cs_hmr_loaidonviInfo()
        {
            this._id_loaidonvi = 0;
            this._tenloai = " ";
            this._ghichu = " ";
            this._capthaotac = 0;

        }
        public int id_loaidonvi
        {
            get
            {
                return this._id_loaidonvi;
            }
            set
            {
                this._id_loaidonvi = value;
            }
        }
        public string tenloai
        {
            get
            {
                return this._tenloai;
            }
            set
            {
                this._tenloai = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }
        public int capthaotac
        {
            get
            {
                return this._capthaotac;
            }
            set
            {
                this._capthaotac = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[5];
            paraName[0] = "@id_loaidonvi";
            paraName[1] = "@tenloai";
            paraName[2] = "@ghichu";
            paraName[3] = "@capthaotac";
            paraName[4] = "@option";
            object[] paraValue = new object[5];
            paraValue[0] = this._id_loaidonvi;
            paraValue[1] = this._tenloai;
            paraValue[2] = this._ghichu;
            paraValue[3] = this._capthaotac;
            paraValue[4] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 5, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[4];
            fields[0] = "id_loaidonvi";
            fields[1] = "tenloai";
            fields[2] = "ghichu";
            fields[3] = "capthaotac";
            list.KetDulieu(myList, "HMR_LOAIDONVI", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_LOAIDONVI", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("tenloai", "id_loaidonvi");
            cb.KetDuLieu(cbo, "HMR_LOAIDONVI", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[4];
            header[0] = "id_loaidonvi";
            header[1] = "tenloai";
            header[2] = "ghichu";
            header[3] = "capthaotac";

            string[] mappingname = new string[4];
            mappingname[0] = "id_loaidonvi";
            mappingname[1] = "tenloai";
            mappingname[2] = "ghichu";
            mappingname[3] = "capthaotac";

            int[] colwidth = new int[4];
            colwidth[0] = 12;
            colwidth[1] = 1200;
            colwidth[2] = 6000;
            colwidth[3] = 12;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_LOAIDONVI", datagrid, csdl.OpenTable("HMR_LOAIDONVI", condition), header, mappingname, colwidth, 4);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_LOAIDONVI", "");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_loaidonvi = Convert.ToInt32(ds.Tables[0].Rows[0]["id_loaidonvi"].ToString().Trim());
                this._tenloai = ds.Tables[0].Rows[0]["tenloai"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._capthaotac = Convert.ToInt32(ds.Tables[0].Rows[0]["capthaotac"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_LOAIDONVI", "");
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
